package com.leo.effects;

import com.almasb.fxgl.dsl.FXGL;
import com.almasb.fxgl.dsl.components.Effect;
import com.almasb.fxgl.entity.Entity;
import com.almasb.fxgl.texture.Texture;
import javafx.util.Duration;
import org.jetbrains.annotations.NotNull;

public class ShipEffect extends Effect {

    private Texture texture;

    public ShipEffect(@NotNull Duration duration) {
        super(duration);
        texture = FXGL.texture("item/armed_ship.png");
    }

    /**
     * 效果结束的时候
     *
     * @param entity
     */
    @Override
    public void onEnd(@NotNull Entity entity) {
        entity.getViewComponent().removeChild(texture);
    }

    /**
     * 效果开始的时候
     *
     * @param entity
     */
    @Override
    public void onStart(@NotNull Entity entity) {
        texture.setTranslateX(entity.getWidth() / 2.0 - texture.getWidth() / 2.0);
        texture.setTranslateY(entity.getHeight() / 2.0 - texture.getHeight() / 2.0);
        entity.getViewComponent().addChild(texture);
    }
}
